<template>
  <div>
    <base-list ref="storehousePlanType"
               :condition="condition"
               :datas.sync="storehousePlanType"
               :pageSearch="pageSearch">
      <el-form :inline="true"
               :model="condition"
               class="search-form"
               slot="search"
               label-width="100px">
        <el-row>
          <el-col :span="8" class="search-width6">
            <el-form-item label="仓库策划类型">
              <el-select v-model="condition['search_EQ_stackPlanType']"
                         placeholder="请选择"
                         clearable>
                <el-option v-for="(item,index) in planTypeList"
                           :key="index"
                           :label="item.desc"
                           :value="item.code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button type="primary"
                       icon="el-icon-search"
                       @click="loadData"
                       class="ml-80">查 询</el-button>
            <!-- <el-button formVisible="true" icon="el-icon-plus" @click="handleDialogFormOpen(false)" v-if="power('WJOB_BASEMGR_VEHICLE:ADD')">
                            新增
                        </el-button> -->
          </el-col>
        </el-row>
      </el-form>
      <el-table slot="list"
                :data="storehousePlanType"
                border
                stripe
                max-height="550">
        <el-table-column type="index"
                         label="序号"
                         width="55">
          <template slot-scope="scope">
            {{ scope.$index+1 }}
          </template>
        </el-table-column>
        <el-table-column prop="stackPlanTypeDesc"
                         label="仓库策划类型"
                         min-width="80"></el-table-column>
        <el-table-column prop="orgName"
                         label="所属单位"
                         min-width="120"></el-table-column>
        <el-table-column prop="warehouseName"
                         label="所属仓库"
                         min-width="80"></el-table-column>
        <el-table-column align="center"
                         label="操作"
                         width="120">
          <template slot-scope="scope">
            <el-button size="small"
                       type="text"
                       @click="handleDialogFormOpen(true,scope.row)">
              编辑
            </el-button>
            <el-button type="text"
                       class="danger"
                       size="small"
                       @click="handleRemove(scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </base-list>
    <storehouse-plan-type-add-form ref="storehousePlanTypeAddForm"
                                   @load="loadData"></storehouse-plan-type-add-form>
    <div style="text-align:center">
      <el-button plain
                 type="info"
                 plain
                 @click="handleRouterPush({path: '/goods/storehouse',name: '仓库管理'})">返回</el-button>
    </div>
  </div>
</template>

<script>
import {
  deleteStorehousePlanType,
  getStorehousePlanTypeList,
  getPlanTypeList
} from '@/api/storehousePlanType/storehousePlanType'
import storehousePlanTypeAddForm from './storehousePlanTypeAddForm'

export default {
  name: 'storehousePlanType',
  components: {
    storehousePlanTypeAddForm
  },
  data() {
    return {
      condition: {}, // 查询条件
      storehousePlanType: [], // table数组
      pageSearch: getStorehousePlanTypeList, // 分页查询api接口
      id: '',
      planTypeList: null
    }
  },
  mounted() {
    getPlanTypeList().then(res => {
      this.planTypeList = res.data.aaData
      console.log('planTypeList')
      console.log(this.planTypeList)
    }),
      this.$nextTick(() => {
        this.loadData()
      })
  },
  methods: {
    loadData() {
      this.$refs.storehousePlanType.loadData()
    },
    handleDialogFormOpen(bool, item) {
      if (bool) {
        let form = JSON.parse(JSON.stringify(item))
        let temp = [
          {
            attrCode: form.attrCode,
            attrName: form.attrName,
            priority: form.priority,
            remark: form.remark
          }
        ]
        this.$refs.storehousePlanTypeAddForm.form = {
          id: form.id,
          stackPlanType: form.stackPlanType,
          stackPlanTypeDesc: form.stackPlanTypeDesc,
          warehouseId: form.warehouseId,
          warehouseName: form.warehouseName,
          orgId: form.orgId,
          orgName: form.orgName,
          factors: form.factors || temp
        }
        this.$refs.storehousePlanTypeAddForm.isEdit = true
        this.$refs.storehousePlanTypeAddForm.dialogForm = true
      } else {
        this.$refs.storehousePlanTypeAddForm.dialogForm = true
      }
    },
    handleRemove(item) {
      this.$confirm(`是否删除该数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteStorehousePlanType(item.id).then(res => {
            this.$message({
              type: 'success',
              message: `删除成功!`
            })
            this.loadData()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    handleRouterPush(val) {
      this.$store.commit('ADD_CACHED_VIEWS', val)
      this.$router.push(val.path)
    }
  }
}
</script>

<style scoped>
</style>
